package example;

import org.junit.Test;

import java.io.File;
import java.io.IOException;

/**
 * 表示文件资源 不能操作内容
 */
public class FileTest {
    @Test
    public void test1() {
        File file = new File("C://");
        System.out.println("file: " + file);
        System.out.println("getAbsolutePath: " + file.getAbsolutePath());
        System.out.println("getAbsoluteFile: " + file.getAbsoluteFile());
        System.out.println("getName: " + file.getName());
        System.out.println("getParent: " + file.getParent());
        System.out.println("getParentFile: " + file.getParentFile());

        System.out.println("exists: " + file.exists());
        System.out.println("isFile: " + file.isFile());
        System.out.println("isDirectory: " + file.isDirectory());

        System.out.println("canExecute:" + file.canExecute());
        System.out.println("canRead:" + file.canRead());
        System.out.println("canWrite:" + file.canWrite());

        System.out.println("lastModified:" + file.lastModified());
        System.out.println("length:" + file.length());

        String names[] = file.list();
        File files []= file.listFiles();

    }

    @Test
    public void test2() {
        File file = new File("C:\\Users\\LiuZijian\\Desktop\\新建文本文档.txt");
        try {
            //rename 源文件必须存在 目标必须不存在
            file.renameTo(new File("C:\\Users\\LiuZijian\\Desktop\\1.txt"));
            file.createNewFile();
            file.mkdir();
            file.mkdirs();
            file.delete();
        }
        catch (IOException e) {
            e.printStackTrace();
        }

    }
}
